<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>闭包</title>
</head>
<body>
    <p>在控制台查看</p>
    <p>闭包：可以访问外部定义的变量，类似于static，可以实现调用一次函数累计计数，而不是从0开始</p>
    <p></p>
    <script>
  function createCounter() {
  let count = 0;
  
  return function() {
    count++;
    return count;
  };
}
const counter = createCounter();
console.log(counter()); // 1
console.log(counter()); // 2
console.log(counter()); //3
    </script>
  
</body>
</html>